//js
$(function(){
var _isSplash = true;
var _$window = $(window);
function init(){
	var gridWidth = 540 + 24;
	var gridHeight = 540;
	onSplashClick();
	$('#whh-btn').click(onBtnReturnClick);
	$('#whb-return').click(onBtnReturnClick);
	_$window.resize(onResize);
	_$window.scroll(onScroll);
	_$window.on('touchstart',onScroll);
	_$window.on('touchmove', onScroll);
	_$window.on('touchend', onScroll);
	//disable vertical scroll
	Draggable.create("#wr-container", {
	    type:"x",
	    edgeTolerance:0.25,
	    edgeResistance:0.85,
	    bounds: {minX:0, maxX:-5400},
	    lockAxis:true,
	    throwProps:true,
	    zIndexBoost:false,
	    snap: {
        x: function(endValue) {
            return Math.round(endValue / gridWidth) * gridWidth;
        },
        y: function(endValue) {
            return Math.round(endValue / gridHeight) * gridHeight;
        }
	    }
	});
	//start
	_$window.resize();
}

function onTouchMove(e) {
	e.preventDefault();
}

function onResize() {
	var w = _$window.width();
	var h = _$window.height();
	if(_isSplash){
		$('#w-splash').css('height', h);
		$('#w-place-holder').css('height', h / 2);
		$('#wh-place-holder').css('height', h);
	}
}

function onScroll(e) {
	var pos = _$window.scrollTop();
	var point = $('#wh-place-holder').offset().top;
	if(pos >= point){
			$('#whb-comment img').last().show().siblings('img').hide();
			$('#whb-like img').last().show().siblings('img').hide();
			$('#whb-share img').last().show().siblings('img').hide();
			$('#wh-btns').addClass('affix wh-btns-stick');
			$('#whb-like span').css('color', 'white');
			$('#whb-return').css('display', 'inline-block');
	}else{
			$('#whb-comment img').first().show().siblings('img').hide();
			$('#whb-like img').first().show().siblings('img').hide();
			$('#whb-share img').first().show().siblings('img').hide();
			$('#wh-btns').removeClass('affix wh-btns-stick');
			$('#whb-like span').css('color', '#C63E3E');
			$('#whb-return').css('display', 'none');
	}
}

//going into the main page
function onSplashClick() {
	var h = _$window.height();
	_isSplash = false;
	//disable vertical scroll
	_$window.off('touchmove', onTouchMove);
	$('#w-splash').addClass('w-splash-fade');
	$('#wh-head').addClass('wh-head-show');
	$('#wh-head a').addClass('wh-head-a-show');
	$('#wh-btns').addClass('wh-btns-show');
}

//coming back to splash page
function onBtnReturnClick() {
	//disable vertical scroll
	_$window.on('touchmove', onTouchMove);
	$('#w-splash').removeClass('w-splash-fade');
	$('#wh-head').removeClass('wh-head-show');
	$('#wh-head a').removeClass('wh-head-a-show');
	$('#wh-btns').removeClass('wh-btns-show');
	$('#w-place-holder').removeClass('w-place-holder-up');
	$('#wh-place-holder').removeClass('wh-place-holder-up');
	_isSplash = true;
	_$window.resize();
}

init();
});